package com.asa.fushu.bean;

/**
 *
 *	复数基于欧拉方程的各种转化
 *
 *
 *
 */
public class Eulerformula {
	
	/**
	 * @author Administrator
	 * @param m	次方
	 * @param n	下标
	 * @return
	 */
	public static Fushu wmn(int m,int n) {
		Fushu result = new Fushu();

		result.real = Math.cos(2*Math.PI*(m%n)/n);
		result.im = Math.sin(2*Math.PI*(m%n)/n);
		
		return result;
	}
	
	
	
	/**
	 * 	欧拉公式
	 * Euler formula
	 * 
	 * Math.exp(i*x) = Math.cos(x)+ i*Math.sin(x)
	 * @param x
	 * @return
	 */
	public static Fushu ei(Fushu_EXI x) {
		
		Fushu result = new Fushu();
		
		result.real = Math.cos(x.x)*x.r;
		result.im = Math.sin(x.x)*x.r;

		return result;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
	}
	
	
	/**
	 * r*Math.cos(x)+ r*i*Math.sin(x)  = r*Math.exp(i*x)
	 * 
	 * 其实这里的x不好却认，我默认它的取值只能是[0,2π],实际上它是一根幅角，而且有时候是逆时针的转
	 * 我这里就不管那么多了
	 * @param asa
	 * @return
	 */
	public static Fushu_EXI ei_ni(Fushu asa) {
		
		double r = asa.length();
		double acos = argz(asa);
		Fushu_EXI result = new Fushu_EXI();
		result.r = r;
		result.x = acos;
		
		return result;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
	}
	
	
	
	public static double argz(Fushu asa) {
		double r = asa.length();
		double cos = asa.real/r;
		double sin = asa.im/r;
		
		double acos = Math.acos(cos);

		if (sin<0) {//这样没问题，挺好的
			acos = acos + Math.PI;
		}
		
		
		return acos;
	}

	
	
	
	
	
	
	
	
	public static void main(String[] args) {
		Fushu_EXI x = new Fushu_EXI();

		x.r = 1;
		x.x = 3*Math.PI/2;
		System.out.println(x);

		Fushu ei = ei(x);
		
		ei.shownumber();
		
		
		
		Fushu_EXI ei_ni = ei_ni(ei);
		System.out.println();
		System.out.println(ei_ni);
	}
	

}
